home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / HUNCHY.ZIP / WALLC.PAS < prev    next >
Pascal/Delphi Source File  |  1980-01-01  |  2KB  |  78 lines

  1. const
  2.   Numbers:set of char=['0'..'9'];
  3. type
  4.   str80=string[80];
  5. var
  6.   Source:text;
  7.   Comp:file of integer;
  8.   Line:str80;
  9.   NewWlCh,NoOfWalls,Weapons:byte;
  10.   Code,LineNo,Ctr,Dat:integer;
  11.  
  12. procedure Wcomp(Dat:integer);
  13. begin
  14.   Write(Comp,Dat);
  15. end;
  16.  
  17. procedure Strip(var St:Str80);
  18. begin
  19.   while (St[1] = ' ') and (Length(St)>0) do St:=Copy(St,2,80);
  20.   while (St[Length(St)] = ' ') and (Length(St)>0) do Dec(St[0]);
  21. end;
  22.  
  23. function Eval(St:Str80):byte;
  24. var
  25.   Tmp:byte;
  26.   Code:integer;
  27. begin
  28.   while not (St[1] in ['-','0'..'9']) and (Length(St)>0) do St:=Copy(St,2,80);
  29.   while not (St[Length(St)] in ['0'..'9']) and (Length(St)>0) do Dec(St[0]);
  30.   Val(St,Tmp,Code);
  31.   if Code>0 then begin
  32.     Writeln('Error line ',LineNo,': ',Line);
  33.     Halt;
  34.   end;
  35.   Eval:=Tmp;
  36. end;
  37.  
  38. begin
  39.   Writeln; Writeln('Hunchback wall compiler'); Writeln;
  40.   NoOfWalls:=0;
  41.   NewWlCh:=255;
  42.   Weapons:=0;
  43.   LineNo:=0;
  44.   Assign(Source,'b:WALLS.TXT');
  45.   Assign(Comp,'c:WALL.DAT');
  46.   Reset(Source); ReWrite(Comp);
  47.   while not eof(Source) do begin
  48.     Readln(Source,Line);
  49.     Inc(LineNo);
  50.     Strip(Line);
  51.     if not ((Line[1]=';') or (Line[0]=#0)) then begin
  52.       if Line[1]='#' then begin
  53.         Inc(NoOfWalls);
  54.         Writeln('Reading wall ',Chr(64+NoOfWalls));
  55.         Wcomp(MaxInt);
  56.         Weapons:=0;
  57.       end;
  58.       case UpCase(Line[1]) of
  59.         'N':Wcomp(0);
  60.         'R':begin Wcomp(1); Writeln('  Rope'); end;
  61.         'G':begin Wcomp(2); Writeln('  Guards'); end;
  62.         'P':begin Wcomp(3); Writeln('  Pitholes'); end;
  63.       end;
  64.       if Line[1] in Numbers then
  65.         if Weapons=0 then begin
  66.           Weapons:=Eval(Line);
  67.           Writeln(Weapons:3,' weapon(s)');
  68.           Wcomp(Weapons);
  69.           for Ctr:=1 to 5*Weapons do begin
  70.             Read(Source,Dat);
  71.             Wcomp(Dat);
  72.           end;
  73.         end;
  74.     end;
  75.   end;
  76.   Close(Source);
  77.   Close(Comp);
  78. end.